package account9_1_1_6;

public class Account {
	private String id;
	private String name;
	private int balance;

	public Account(String id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public Account(String id, String name, int balance) {
		super();
		this.id = id;
		this.name = name;
		this.balance = balance;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getBalance() {
		return balance;
	}

	public int credit(int amount) {
		return balance + amount;
	}

	public int debit(int amount) {
		if (amount <= balance) {
			return balance - amount;
		} else {
			System.out.println("Amount exceeded balance");
			return balance;
		}
	}

	public int transferTo(Account another, int amount) {
		if (amount <= balance) {
			return another.balance + amount;
		} else {
			System.out.println("Amount exceeded balance");
			return balance;
		}

	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return id.hashCode() + name.hashCode() + Integer.hashCode(balance);
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(!(obj instanceof Account))
			return false;
		Account account = (Account) obj;
		return this.id == account.id && this.name == account.name && this.balance == account.balance;
	}

	@Override
	public String toString() {
		return "Account [id=" + id + ", name=" + name + ", balance=" + balance + "]";
	}
}
